package eo.entityManager.locator.impl;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Query;

import eo.entityManager.locator.EntityManagerLocator;

public class EntityManagerWrapper implements EntityManager, Serializable {
    private static final long serialVersionUID = -6325391213748387014L;
    private final EntityManager entityManager;
    private final EntityManagerLocator locator;

    public EntityManagerWrapper(EntityManager entityManager,
            EntityManagerLocator locator) {
        super();
        this.entityManager = entityManager;
        this.locator = locator;
    }

    /**
     * 
     * @see javax.persistence.EntityManager#clear()
     */
    public void clear() {
        entityManager.clear();
    }

    /**
     * 
     * @see javax.persistence.EntityManager#close()
     */
    public void close() {
        locator.closeEntityManager();
    }

    /**
     * @param entity
     * @return
     * @see javax.persistence.EntityManager#contains(java.lang.Object)
     */
    public boolean contains(Object entity) {
        return entityManager.contains(entity);
    }

    /**
     * @param name
     * @return
     * @see javax.persistence.EntityManager#createNamedQuery(java.lang.String)
     */
    public Query createNamedQuery(String name) {
        return entityManager.createNamedQuery(name);
    }

    /**
     * @param sqlString
     * @param resultClass
     * @return
     * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String,
     *      java.lang.Class)
     */
    @SuppressWarnings("unchecked")
    public Query createNativeQuery(String sqlString, Class resultClass) {
        return entityManager.createNativeQuery(sqlString, resultClass);
    }

    /**
     * @param sqlString
     * @param resultSetMapping
     * @return
     * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String,
     *      java.lang.String)
     */
    public Query createNativeQuery(String sqlString, String resultSetMapping) {
        return entityManager.createNativeQuery(sqlString, resultSetMapping);
    }

    /**
     * @param sqlString
     * @return
     * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String)
     */
    public Query createNativeQuery(String sqlString) {
        return entityManager.createNativeQuery(sqlString);
    }

    /**
     * @param qlString
     * @return
     * @see javax.persistence.EntityManager#createQuery(java.lang.String)
     */
    public Query createQuery(String qlString) {
        return entityManager.createQuery(qlString);
    }

    /**
     * @param <T>
     * @param entityClass
     * @param primaryKey
     * @return
     * @see javax.persistence.EntityManager#find(java.lang.Class,
     *      java.lang.Object)
     */
    public <T> T find(Class<T> entityClass, Object primaryKey) {
        return entityManager.find(entityClass, primaryKey);
    }

    /**
     * 
     * @see javax.persistence.EntityManager#flush()
     */
    public void flush() {
        entityManager.flush();
    }

    /**
     * @return
     * @see javax.persistence.EntityManager#getDelegate()
     */
    public Object getDelegate() {
        return entityManager.getDelegate();
    }

    /**
     * @return
     * @see javax.persistence.EntityManager#getFlushMode()
     */
    public FlushModeType getFlushMode() {
        return entityManager.getFlushMode();
    }

    /**
     * @param <T>
     * @param entityClass
     * @param primaryKey
     * @return
     * @see javax.persistence.EntityManager#getReference(java.lang.Class,
     *      java.lang.Object)
     */
    public <T> T getReference(Class<T> entityClass, Object primaryKey) {
        return entityManager.getReference(entityClass, primaryKey);
    }

    /**
     * @return
     * @see javax.persistence.EntityManager#getTransaction()
     */
    public EntityTransaction getTransaction() {
        return entityManager.getTransaction();
    }

    /**
     * @return
     * @see javax.persistence.EntityManager#isOpen()
     */
    public boolean isOpen() {
        return entityManager.isOpen();
    }

    /**
     * 
     * @see javax.persistence.EntityManager#joinTransaction()
     */
    public void joinTransaction() {
        entityManager.joinTransaction();
    }

    /**
     * @param entity
     * @param lockMode
     * @see javax.persistence.EntityManager#lock(java.lang.Object,
     *      javax.persistence.LockModeType)
     */
    public void lock(Object entity, LockModeType lockMode) {
        entityManager.lock(entity, lockMode);
    }

    /**
     * @param <T>
     * @param entity
     * @return
     * @see javax.persistence.EntityManager#merge(java.lang.Object)
     */
    public <T> T merge(T entity) {
        return entityManager.merge(entity);
    }

    /**
     * @param entity
     * @see javax.persistence.EntityManager#persist(java.lang.Object)
     */
    public void persist(Object entity) {
        entityManager.persist(entity);
    }

    /**
     * @param entity
     * @see javax.persistence.EntityManager#refresh(java.lang.Object)
     */
    public void refresh(Object entity) {
        entityManager.refresh(entity);
    }

    /**
     * @param entity
     * @see javax.persistence.EntityManager#remove(java.lang.Object)
     */
    public void remove(Object entity) {
        entityManager.remove(entity);
    }

    /**
     * @param flushMode
     * @see javax.persistence.EntityManager#setFlushMode(javax.persistence.FlushModeType)
     */
    public void setFlushMode(FlushModeType flushMode) {
        entityManager.setFlushMode(flushMode);
    }

}
